<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('title'=>'名片列表','op'=>'list','action'=>'card',),
	
);
set_html('tabs',$tabs);
/*******list*******/
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['name']){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$fields=array('id','mid','name','avatar','company','department','position','mobile','createtime');
	$list=pdo_getslice('jy_business_card_card',$params,array($pindex,$psize),$total,$fields,'','id desc');
	
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array('type'=>'list','list'=>array(
		'data'=>'list',
		'key'=>'mid',
		'edit'=>true,
		'del_one'=>true,
		'del_op'=>'list_del',
		'del_title'=>'删除',
		'delall'=>true,
		'del_message'=>'确定要删除吗？',
		'pagelist'=>true,
		'list'=>array(
			array(
				array('type'=>'string','name'=>'name','title'=>'名字',),
			),
			array(
				array('type'=>'image','name'=>'avatar','title'=>'头像',),
			),
			array(
				array('type'=>'string','name'=>'company','title'=>'公司',),
			),
			array(
				array('type'=>'string','name'=>'department','title'=>'部门',),
			),
			array(
				array('type'=>'string','name'=>'position','title'=>'职务',),
			),
			array(
				array('type'=>'string','name'=>'mobile','title'=>'电话',),
			),
			array(
				array('type'=>'time','name'=>'createtime','title'=>'创建时间'),
			),
		),
	),'search_one'=>array('add'=>false,'name'=>'name',),);

	
	set_html('title','名片列表');
	exi($return);
}
if($_RQ['op']=='list_del'){
	$dels=array();
	if($_RQ['del']){
		$dels=str_2_array($_RQ['del']);
	}
	if($_RQ['mid']){
		$dels[]=intval($_RQ['mid']);
	}
	if(empty($dels)){
		exi('没有选择要删除的项目！','error');
	}
	foreach($dels as $mid){
		pdo_delete('jy_business_card_card',array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
		pdo_delete('jy_business_card_member_secret',array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('删除成功！');
}
/*******list*******/
/*******edit*******/
if($_RQ['op']=='edit'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$data=array_fields(array('name','avatar','company','department','position','mobile','wechat_name','attention'),$post);

		$id=intval($post['id']);
		if(!$id){
			exi('页面参数错误！','error');
		}
		pdo_update('jy_business_card_card',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('操作成功！','','card/list');
	}
	$id=intval($_RQ['mid']);
	if(!$id){
		exi('页面参数错误！','error');
	}
	$item=pdo_get('jy_business_card_card',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$return['item']=$item;


	$return['htmls']=array('type'=>'edit','desc'=>'编辑名片信息','edit'=>array(
		array('title'=>'姓名','help'=>'设置姓名','name'=>'name','type'=>'string',),
		array('title'=>'头像','help'=>'','name'=>'avatar','type'=>'image',),
		array('title'=>'公司','help'=>'请填写公司名称','name'=>'company','type'=>'string',),
		array('title'=>'部门','help'=>'','name'=>'department','type'=>'string',),
		array('title'=>'职位','help'=>'','name'=>'position','type'=>'string',),
		array('title'=>'手机','help'=>'','name'=>'mobile','type'=>'string',),
		array('title'=>'微信号','help'=>'','name'=>'wechat_name','type'=>'string',),
		array('title'=>'个性签名','help'=>'','name'=>'attention','type'=>'string',),
	),);
	set_html('title','名片编辑');
	exi($return);
}
/*******edit*******/
/*******op*******/
exi('访问的页面功能不存在！','error');